package com.ocom.human.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.human.EntityPersonTag;
import com.ocom.common.entity.human.EntityPersonnelFeature;
import com.ocom.common.request.human.GetPerFeatureResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface IDaoPersonnelFeature extends BaseMapper<EntityPersonnelFeature> {

    @Select({"<script>",
            "select " +
                    " p.com_id,p.p_id,p.p_code,p.p_name,p.dept_id,d.dept_name,p.p_sex, f.`version`," +
                    " f.p_photo_url, f.feature,f.probability," +
                    " f.p_photo_url2, f.feature2,f.probability2," +
                    " p.p_photo_url as pUrl, p.p_photo_url2 as pUrl2," +
                    " f.create_time,f.update_time " +
                    " from personnel_info p \n" +
                    " left join dept_info d  on  p.com_id=d.com_id and  p.dept_id=d.dept_id\n" +
                    " left join personnel_feature f on  p.com_id=f.com_id and p.p_id=f.p_id\n" +
                    " Where p.com_id=#{comId} " +
                    " and p.status=0 " +
                    " <when test=\"pId !=null and  pId !='-1'\" > " +
                    " and p.p_id=#{pId}" +
                    " </when>" +
                    " <when test=\" deptIds != null and deptIds.size() > 0 \" > " +
                    "   AND  p.dept_id in " +
                    " <foreach collection='deptIds' item='item' open='(' separator=',' close=')'>" +
                    "   #{item}" +
                    " </foreach>" +
                    " </when> " +
                    " <when test=\"pName !=null and  pName !=''\" > " +
                    " AND p.p_name LIKE concat('%', #{pName}, '%')" +
                    " </when>" +
                    " <when test=\"pCode !=null and  pCode !=''\" > " +
                    " and p.p_code = #{pCode}" +
                    " </when>" +
                    " <when test=\" versions != null and versions.size() > 0 \" > " +
                    "  AND  ( f.version is null " +
                    "  OR  f.version in " +
                    " <foreach collection='versions' item='item' open='(' separator=',' close=')'>" +
                    "   #{item}" +
                    " </foreach>" +
                    " ) " +
                    " </when> " +
                    " <when test=\"probabilityMin != null and probabilityMin > 0\" > " +
                    " and ( f.probability &gt;= #{probabilityMin} or f.probability2 &gt;= #{probabilityMin} ) " +
                    " </when>" +
                    " <when test=\"probabilityMax != null and probabilityMax > 0\" > " +
                    " and ( f.probability &lt;= #{probabilityMax} or f.probability2 &lt;= #{probabilityMax} )" +
                    " </when>" +
                    " <when test=\"startTime != null\" > " +
                    " and f.update_time &gt;= #{startTime}" +
                    " </when>" +
                    " <when test=\"endTime != null\" > " +
                    " and f.update_time &lt;= #{endTime}" +
                    " </when>" +
                    " order  by f.update_time  desc " +
                    "</script>"})
    List<GetPerFeatureResponse> getPerFeature(Long comId, Long pId, List<Integer> deptIds, String pName, String pCode, List<String> versions, Float probabilityMin, Float probabilityMax, Date startTime, Date endTime);
}
